import 'package:flutter/material.dart';
import 'package:nyh_motorcade_app/entity/transaction_flow_entity.dart';
import 'package:nyh_motorcade_app/routes/routes.dart';
import 'package:nyh_motorcade_app/styles/colors.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:nyh_motorcade_app/utils/format_utils.dart';
import 'package:nyh_motorcade_app/widgets/flexible_icon_text.dart';
import 'package:nyh_motorcade_app/widgets/text_with_icon.dart';
import 'package:get/get.dart';

class TransactionFlowItem extends StatelessWidget {
  final TransactionFlowPageVoItem entity;
  final FocusNode? focusNode;

  TransactionFlowItem(this.entity, {this.focusNode});

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colours.color_white,
      margin: EdgeInsets.only(bottom: 12.w),
      width: double.infinity,
      child: Material(
        child: InkWell(
          onTap: () {
            if (focusNode != null) {
              focusNode!.unfocus();
            }
            Get.toNamed(Routes.transactionFlowDetails, arguments: entity.id);
          },
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Padding(
                padding: EdgeInsets.symmetric(vertical: 6.w, horizontal: 16.w),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Expanded(
                      child: Text(
                        entity.stationName ?? "",
                        style: TextStyle(
                          color: Colours.color_text_theme,
                          fontSize: 16.sp,
                          fontWeight: FontWeight.bold,
                        ),
                        maxLines: 1,
                        overflow: TextOverflow.ellipsis,
                      ),
                    ),
                    SizedBox(
                      width: 10.w,
                    ),
                    Text(
                      FormatUtils.formatMoney(entity.orderAmount),
                      style: TextStyle(
                        color: Colours.color_text_theme,
                        fontSize: 20.sp,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ],
                ),
              ),
              Divider(
                color: Colours.color_background,
                height: 1.w,
                thickness: 1.w,
              ),
              Container(
                padding: EdgeInsets.symmetric(vertical: 10.w, horizontal: 16.w),
                child: Stack(
                  alignment: AlignmentDirectional.centerEnd,
                  children: [
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        FlexibleIconText(
                          icon: Image.asset(
                            "images/ic_company.png",
                            height: 14.w,
                            width: 14.w,
                            color: Colours.color_6f7082,
                          ),
                          textList: entity.subCompanyList,
                          text: entity.customersName,
                          iconTextPadding: 5.w,
                        ),
                        SizedBox(
                          height: 5.w,
                        ),
                        FlexibleIconText(
                          icon: Image.asset(
                            "images/ic_motorcade.png",
                            height: 14.w,
                            width: 14.w,
                            color: Colours.color_6f7082,
                          ),
                          text: entity.motorcadeName,
                          secondText: entity.vehicleNumber,
                          iconTextPadding: 5.w,
                        ),
                        SizedBox(
                          height: ((entity.motorcadeName ?? "").isNotEmpty || (entity.vehicleNumber ?? "").isNotEmpty) ? 5.w : 0,
                        ),
                        Row(
                          children: [
                            TextWithIcon(
                              text: entity.oilName ?? "",
                              iconName: "images/ic_oil.png",
                              iconHeight: 14.w,
                              iconWidth: 14.w,
                              iconColor: Colours.color_6f7082,
                              textIconPadding: 5.w,
                            ),
                            Visibility(
                              visible: (entity.price ?? 0.0) > 0.0,
                              child: Text(
                                "  l  ",
                                style: TextStyle(color: Colours.color_e7e7ea, fontSize: 12.sp),
                              ),
                            ),
                            TextWithIcon(
                              text: "${FormatUtils.formatMoney(entity.price)}元/升",
                              iconName: "images/ic_rmb.png",
                              iconHeight: 14.w,
                              iconWidth: 14.w,
                              iconColor: Colours.color_6f7082,
                              textIconPadding: 5.w,
                            ),
                            Visibility(
                              visible: (entity.orderQuantity ?? 0.0) > 0.0,
                              child: Text(
                                "  l  ",
                                style: TextStyle(color: Colours.color_e7e7ea, fontSize: 12.sp),
                              ),
                            ),
                            TextWithIcon(
                              text: "${FormatUtils.formatMoney(entity.orderQuantity)}升",
                              iconName: "images/ic_liters.png",
                              iconHeight: 14.w,
                              iconWidth: 14.w,
                              iconColor: Colours.color_6f7082,
                              textIconPadding: 5.w,
                            ),
                          ],
                        ),
                        SizedBox(
                          height: 5.w,
                        ),
                        TextWithIcon(
                          text: entity.tradingTime ?? "",
                          iconName: "images/ic_date.png",
                          iconHeight: 14.w,
                          iconWidth: 14.w,
                          iconColor: Colours.color_6f7082,
                          textIconPadding: 5.w,
                        ),
                      ],
                    ),
                    Visibility(
                      visible: (entity.valid ?? 0) == 0,
                      child: Image.asset("images/ic_invalid.png"),
                    ),
                  ],
                ),
              ),
              Divider(
                color: Colours.color_background,
                height: 1.w,
                thickness: 1.w,
              ),
              Container(
                padding: EdgeInsets.symmetric(vertical: 8.w, horizontal: 16.w),
                child: Text(
                  "交易流水号：${entity.tradingSerialNumber}",
                  style: TextStyle(
                    color: Colours.color_cfcfd5,
                    fontSize: 12.sp,
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
